package com.ruoyi.system.controller;

import com.ruoyi.system.domain.imgBrowse;
import com.ruoyi.system.service.ImgBrowseService;
import com.ruoyi.system.service.Impl.ImgBrowseServiceImpl;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.IOException;

@Controller
@RequestMapping("/system/imgDetail")
public class imgDetaills {

    private String prefix = "other/imgDetail";

    @Autowired(required = false)
    private ImgBrowseService imgBrowseService;

    @Autowired(required = false)
    private ImgBrowseServiceImpl imgBrowseServiceImpl;


    @RequiresPermissions("system:other:imgDetail")
    @GetMapping("/findImgDetailById/{id}")
    public String config(@PathVariable("id") String imgId, ModelMap map)
    {
        imgBrowse imgBrowse = imgBrowseService.findUploadImagePathByImageId(imgId);
        try {
            imgBrowse.setBaseImg(imgBrowseServiceImpl.base64Image(imgBrowse.getImagePath()));
        } catch (IOException e) {
            e.printStackTrace();
        }
        map.put("imgId", imgId);
        map.put("imgBrowse", imgBrowse);
        return prefix + "/imgDetail";
    }
}
